<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<link href="./css/ltcss.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PayChannel</title>
<link href="styles/general.css" rel="stylesheet" type="text/css">
<link href="styles/main.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript" src="js/validator.js"></script>

<script language="javascript" type="text/javascript" src="js/DatePicker4.72/WdatePicker.js"></script>
<script src="js/jquery/jquery-1.3.2.js" type="text/javascript"></script>
</head>

<body>
<form id="form1" name="form1" method="post" action="channel_save.do?msg=<s:property value="msg" />" onsubmit="return txcheck();">
 <input type="hidden" name="model.id" id="model.id" value="<s:property value="model.id"/>" />
 <input type="hidden" name="txt_keyword" id="txt_keyword" value="<s:property value="txt_keyword"/>" />
 <h1>
        <span class="action-span"><a href="channel_list.do">渠道列表</a></span> <span
            class="action-span1"><a href="">
                首页</a> </span><span id="search_id" class="action-span1">- 渠道管理 </span>
        <div style="clear: both">
        </div>
    </h1>
 <div style="margin-bottom: 5px;" class="list-div">
        <table width="100%" cellspacing="1" cellpadding="3">
            <tbody>
                <tr>
                    <th colspan="2">
                     		   基本信息
                    </th>
                </tr>
                <tr> 
				    <td  class="label"><div align="right">渠道名称：</div></td> 
				    <td width="80%">
					    <input id="model.name" name="model.name" type="text" size="60" 
          					value="<s:property value="model.name" />"  onblur="formvalidator(this)"/>
						<span
                           class="require-field">*</span>&nbsp;
                        <span id="CompareValidator1" style="color:Red;visibility:hidden;">不能为空</span><br />
                    </td>
				  </tr>
				  <tr> 
				    <td class="label"><div align="right">公司全称：</div></td> 
				    <td >
					   <input id="model.company" name="model.company" type="text" size="60"  value="<s:property value="model.company" />" />
					   <span class="require-field">*</span>&nbsp;
                        <span id="CompareValidator2" style="color:Red;visibility:hidden;">不能为空</span><br />
                    </td>
				  </tr>
				  <tr> 
				    <td class="label"><div align="right">合作方式：</div></td> 
				    <td >
					   <select id="model.cooperationtype" name="model.cooperationtype">
					   		<option value="cps" <s:if test="model.cooperationtype.indexOf('cps')>-1">selected</s:if>>cps</option>
					   		<option value="cpa" <s:if test="model.cooperationtype.indexOf('cpa')>-1">selected</s:if>>cpa</option>
					   </select>
					<br />
                    </td>
				  </tr>
				   <tr> 
				    <td class="label"><div align="right">负责人：</div></td> 
				    <td >
					   <input id="model.bd" name="model.bd" type="text" size="60"  value="<s:property value="model.bd" />" />
                    </td>
				  </tr>
				   <tr> 
				    <td class="label"><div align="right">签订日期：</div></td> 
				    <td >
					    <input type="text" size="20" name="model.contractDate" id="model.contractDate" 
					    onFocus="WdatePicker({isShowWeek:true,dateFmt:'yyyy-MM-dd',skin:'whyGreen'})" 
					    onblur="formvalidator(this)" value="<s:property value="model.contractDate" />"/>
                    </td>
				  </tr>
				   <tr> 
				    <td class="label"><div align="right">到期日期：</div></td> 
				    <td >
				    	<input type="text" size="20" name="model.contractEnd" id="model.contractEnd" 
					    onFocus="WdatePicker({isShowWeek:true,dateFmt:'yyyy-MM-dd',skin:'whyGreen'})" 
					    onblur="formvalidator(this)" value="<s:property value="model.contractEnd" />"/>
                    </td>
				  </tr>
				   <!-- tr> 
				    <td class="label"><div align="right">平台名称和分成类型：</div></td> 
				    <td >	
					    <input id="model.terraceName" name="model.terraceName" type="text" size="10"  value="<s:property value="model.terraceName" />" />
					    <select name="model.dividetype" id="model.dividetype">
						     			<option value="自有" <s:if test="model.dividetype=='自有'">selected</s:if> >自有</option>
						    			<option value="官方" <s:if test="model.dividetype=='官方'">selected</s:if> >官方</option>
					    </select>
                    </td>
				  </tr -->
				  <tr>
				
	            <td class="label">&nbsp;<font color="red">(*)</font>开通平台：<input type="checkbox" onclick="manage_sp_checkallprovince(this);" /></td>
	      		
	      		<td class="label" colspan="2">
		      		<div class="list-div">
			      		<table width="100%" border="0" cellspacing="0" cellpadding="0" >
			      			<tr style="visibility: true">			      				
	      					<s:iterator value="terraceNameList" status="tn">
	      						<s:if test="#tn.index>0&&#tn.index%5==0"></tr><tr></s:if>
				    			 <td width="10%" class="table_w2" align="left">&nbsp;&nbsp;
				    			 <input type="checkbox" onclick="ckbox(this);" id="checkboxs"  name="ckb_province" value="<s:property value="id" />" 
				    			<s:if test="terraceIds.indexOf(','+id+',')!=-1">checked</s:if> >&nbsp;<s:property value="operatorsName"/></td>						    			 
				 			</s:iterator>						 		
						  </tr>
			      		</table>
		      		</div>
	      		
		      		<div class="list-div">
		      			<table id="mytb" width="100%" style="display: block;"  cellspacing="2" cellpadding="2" >
		        			<tr>
					    		<td class="label" width="15%" align="center">平台名称：</td> 
				    			<td class="label" width="15%" align="center">渠道平台接入ID：</td>
							    <td class="label" width="15%" align="center">合同分成：</td> 
							    <td class="label" width="15%" align="center">分成类型：</td> 
						    	<td class="label" width="15%" align="center">渠道账户名：</td> 
						    	<td class="label" width="15%" align="center">渠道密码：</td> 
						    	<td class="label" width="15%" align="center">描述：</td> 
				    		</tr>	
		        			<s:iterator value="terracelist" status="t">
					    		<tr id="tr_terrace_<s:property value="terraceId" />" <s:if test="terraceIds.indexOf(','+terraceId+',')==-1">style="display: none;"</s:if>>
				   					<td class="label" width="15%" align="center"> 
				   						<s:property value="operatorsName" />
				   						<input type="hidden" name="channelTerraceInfos[<s:property value="#t.index" />].id" value="<s:property value="id" />" />
				   					    <input type="hidden" name="channelTerraceInfos[<s:property value="#t.index" />].channelId" value="<s:property value="model.id" />" />
				   					    <input type="hidden" name="channelTerraceInfos[<s:property value="#t.index" />].terraceId" value="<s:property value="terraceId" />" /> 
				   					</td>
			       					<td class="label" width="15%" align="center">
			       						<s:if test="relevanceid.length()>0">
											<input id="<s:property value="terraceId" />" name="channelTerraceInfos[<s:property value="#t.index" />].relevanceid" type="text" size="8"  value="<s:property value="relevanceid" />" />
			       						</s:if>
			       						<s:else>
			       							<input id="<s:property value="terraceId" />" name="channelTerraceInfos[<s:property value="#t.index" />].relevanceid" type="text" size="8"  value="<s:property value="model.id" />" />
			       						</s:else>
					   				</td>
					   				<td class="label" width="15%" align="center">
										<input id="contractdivide" name="channelTerraceInfos[<s:property value="#t.index" />].contractdivide" type="text" size="8"  value="<s:property value="contractdivide" />" />
									</td>
									<td class="label" width="15%" align="center">
										<select name="channelTerraceInfos[<s:property value="#t.index" />].dividetype" id="dividetype">
							    			<option value="自有" <s:if test="dividetype=='自有'">selected</s:if> >自有</option>
							    			<option value="官方" <s:if test="dividetype=='官方'">selected</s:if> >官方</option>
						    			</select>
									</td>
									<td class="label" width="15%" align="center">
										<input id="channelName" name="channelTerraceInfos[<s:property value="#t.index" />].channelName" type="text" size="8"  value="<s:property value="channelName" />" />
									</td>
									<td class="label" width="15%" align="center">
										<input id="channelpass" name="channelTerraceInfos[<s:property value="#t.index" />].channelpass" type="text" size="8"  value="<s:property value="channelpass" />" />
									</td>
									<td class="label" width="15%" align="center">
										<textarea id="glremark" name="channelTerraceInfos[<s:property value="#t.index" />].glremark"  rows="2" cols="20">
											<s:property value="glremark" />
										</textarea>
					        		</td>
					    		</tr>
				    		</s:iterator>
						</table>
					</div>
	      		</td>
	      		
	      		</tr>
				  <tr> 
				    <td class="label"><div align="right">描述：</div></td> 
				    <td >
					   <textarea name="model.remark" id="model.remark" style="width:839px;height:115px"><s:property value="model.remark" /></textarea>
                    </td>
				  </tr>            
				<tr>
		           <td colspan="5" align="center">
		               <s:if test="isUpdate.equals('true')">
						<input type="submit" value=" 确定 " class="button" />
							&nbsp;&nbsp;&nbsp;
		                  <input type="reset" value=" 重置 " class="button" />
		               </s:if>
		            </td>
          		</tr>
	 	</tbody>
	 </table>
 </div>
</form>
 <!--Bottom开始-->
<div id="footer">
<br />
<s:property value="bottom"/></div>
<!--Bottom结束--> 
<script type="text/javascript">
var arry=new Array();
var oldarry =new Array();
Array.prototype.indexOf = function(val) {
       for (var i = 0; i < this.length; i++) {
           if (this[i] == val) return i;
       }
       return -1;
};
 Array.prototype.remove = function(val) {
     var index = this.indexOf(val);
     if (index > -1) {
         this.splice(index, 1);
     }
 };
 // 把选中了的平台放到oldarry中
 goInit();
 function goInit(){
 	$("input[id='checkboxs']:checkbox").each(function(){
         if($(this).attr("checked")){
        	 oldarry.push($(this).val());
         }
     })
 }
 arry=oldarry;
function txcheck(){
	return formvalidator("all");
}
var flag=0;
function formvalidator(obj)
{
	// 校验平台
	for(var i=0;i<arry.length;i++){
		var dd =document.getElementById(arry[i]).value;
		if(dd.length==0){
			alert("关联ID不能为空!");
			return false;
		}
	}
	var controlId = "all";
	 if (typeof(obj) != "string" )
	 {
		 controlId = obj.id;
	 }
	if(controlId=="all" || controlId=="model.name")
	{
		if(Utils.trim(document.getElementById("model.name").value)=="")
		{
			$("#CompareValidator1").text("不能为空！");
			document.getElementById("CompareValidator1").style.visibility="visible";
			return false;
		}
		else
		{
			$.get("channel_chkchannelname.do?model.name="+Utils.trim(document.getElementById("model.name").value),function(data){
				if(data=="1"){
					$("#CompareValidator1").text("名称重复，请检查！");
					document.getElementById("CompareValidator1").style.visibility="visible";
					flag=1;
					return false;
				}else{
					document.getElementById("CompareValidator1").style.visibility="hidden";
					flag=0;
				}
			});
		}
	}
	if(controlId=="all" || controlId=="model.company")
	{
		if(Utils.trim(document.getElementById("model.company").value)=="")
		{
			document.getElementById("CompareValidator2").style.visibility="visible";
			return false;
		}
		else
		{
			document.getElementById("CompareValidator2").style.visibility="hidden";
		}
	}	
	if(flag>0){
		return false;
	}
	return true;
}

function manage_sp_checkallprovince(obj)
{
	var ckbs = document.getElementsByName("ckb_province");
	if (obj.checked == true)
	{
		for (var n = 0; n < ckbs.length; n++)
		{	
			arry.push(ckbs[n].value);
			ckbs[n].checked = true;
			document.getElementById("tr_terrace_" + ckbs[n].value).style.display = "";			
		}
	}
	else
	{
		for (var n = 0; n < ckbs.length; n++)
		{
			arry.remove(ckbs[n].value);
			ckbs[n].checked = false;
			document.getElementById("tr_terrace_" + ckbs[n].value).style.display = "none";			
		}
	}
}

function chkAll(vl,name)
{
	var v = document.getElementsByName(name);
	for(var i=0;i<v.length;i++)
	{
		v[i].checked=vl;
	}
	
}
function ckbox(obj){	
	if(obj.checked) {
		arry.push(obj.value);
		document.getElementById("tr_terrace_" + obj.value).style.display = "";
	}
	else {
		arry.remove(obj.value);
		document.getElementById("tr_terrace_" + obj.value).style.display = "none";
	}
}
</script> 
</body>
</html>